﻿using ReflectionStudio.Core.Events;
using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace WPFExcelReport
{
    public partial class TSBDE
    {

        public TSBDE()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VAMSTAMM();
            this.DataContext = MV;
            InitializeComponent();
            ART = app.TERMNO.PadRight(8);
        }
        public override void Window_Loaded(object sender, RoutedEventArgs e)
        {
            base.Window_Loaded(sender, e);
        }
        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
        }
        public void Search()
        {
            if (!IsShift)
            {
                SHIFT = "1";
            }
            else
            {
                if (SHIFT == "")
                {
                    MessageBox.Show("请选择班次");
                    return;
                }
            } 

            if (ART.Trim() == "")
            {
                MessageBox.Show("请输入机台号码");
                return;
            }
            if (ENVMAIN.ContainsKey("BELEGA"))
                ENVMAIN.Remove("BELEGA");
            if (ENVMAIN.ContainsKey("LFDNRA"))
                ENVMAIN.Remove("LFDNRA");
            dwData = TMV.TBMain.NewRow();
            dwData["AMMANDANT"] = app.Mandant;
            dwData["AMBDEMA"] = ART;
            SResult = TMV.QAM07(dwData);
            MergeData(SResult, true);
            if (TBMain.Rows.Count > 0)
                IsMachineReady = true;
        }

        public override void QueryCommand(object sender, RoutedEventArgs e)
        {
            try
            {
                this.Focus();
                TextBox tb = sender as TextBox;
                Search();
                tb.Focus();
                base.QueryCommand(sender, e);

            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }

        private void StartQICommand(object sender, RoutedEventArgs e)
        {
            Search();
        }
    }
}
